#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int y = 0, m = 0;
	int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	while (~(scanf("%d%d", &y, &m)))
	{
		int day = days[m - 1];
		if ((y %4==0 && y % 100!= 0 )||(y %400 == 0))
		{
			day += 1;
		}
		printf("%d", day);
	}
	return 0;
}